using UnityEngine;
using System.Collections;

public class cEngine : MonoBehaviour {
	
	public ParticleSystem EngineBlowSmoke;
	
	public float MaxRPM;		// 최대 회전수
	
	public float MaxTorque;		// 최대 토크
	
	public float MaxDamage;		// 최대 충격량
	
	public float Efficiency;	// 연비
	
	private float _CurrentRPM;
	
	private float _CurrentDamage;
	
	// Use this for initialization
	void Start () {
		
		_CurrentRPM = 0f;
		
		EngineBlowSmoke = (ParticleSystem)Instantiate(EngineBlowSmoke);
		EngineBlowSmoke.transform.parent = transform;
		
		EngineBlowSmoke.Stop();

	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	public void AddDamage( float damage )
	{

		_CurrentDamage += damage;
		
		if ( _CurrentDamage > MaxDamage * 0.1f )
		{
			
			if ( _CurrentDamage > MaxDamage ) _CurrentDamage = MaxDamage;
			
			EngineBlowSmoke.startSize = _CurrentDamage / MaxDamage * 10f;
			
			EngineBlowSmoke.emissionRate = _CurrentDamage / MaxDamage * 20f;
			
			if ( !EngineBlowSmoke.enableEmission )
				
				EngineBlowSmoke.enableEmission = true;
			
			if ( !EngineBlowSmoke.isPlaying )
				EngineBlowSmoke.Play();
			
		}

	}
	
}
